#include "Sound3D.h"
#include "Audio.h"
#include "AllocationManager.h"
#include "Error.h"

namespace Engine
{
	bool Sound3D::Load(const std::string& filename)
	{
		m_sound = TheAudio::Instance() ->m_audioEngine ->play3D(filename.c_str(), 
			irrklang::vec3df(0,0,0), false, true, false, irrklang::ESM_AUTO_DETECT, true);

		if(m_sound)
		{
			#ifdef MEM_DEBUG
				TheAllocationManager::Instance() ->AddAllocation(Allocation(&m_sound, 4,__FILE__, __LINE__));
			#endif //MEM_DEBUG

			m_name = filename;
		}
		if(!m_sound) 
		{
			Error("Unable to load 2D Sound: " + filename);
			return false;
		}
		return true;
	}

	bool Sound3D::Load(rapidxml::xml_node <>* node)
	{
		if(!node ->first_node("FileName"))
		{
			Error("Unable to find Sound3D FilePath in xml file");
			return false;
		}

		return Load(node ->first_node("FileName") ->value());
	}

	void Sound3D::SetVel(const Vec3& vel)
	{
		if(m_sound) 
		{
			m_sound ->setVelocity(irrklang::vec3df(vel.x, vel.y, vel.z));
			m_vel = vel;
		}
	}

	void Sound3D::SetPos(const Vec3& pos) 
	{
		if(m_sound) 
		{
			m_pos = pos;
			m_sound ->setPosition(irrklang::vec3df(pos.x, pos.y, pos.z));
		}
	}
}
